package Huihu.src.Network;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

//还是要等待客户端的连接
public class UdpTestServerdome02 {
    public static void main(String[] args) throws IOException {
        //1、开放端口
        DatagramSocket socket=new DatagramSocket(8806);
        //2、接受数据
        byte [] bus=new byte[1024];
        DatagramPacket packet=new DatagramPacket(bus,0,bus.length);
        //阻塞接受
        socket.receive(packet);
        //打印出IP地址
        System.out.println(packet.getAddress().getHostAddress());
        //打印接收的数据
        System.out.println(new String(packet.getData(),0, packet.getLength()));
        //关闭连接
        socket.close();
    }
}
